<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/6/29 0029
 * Time: 下午 16:18
 */

use yii\widgets\Pjax;

$rankResult = $playerModel->getActivityRank();
?>

<?php

\yii\bootstrap\Modal::begin([
    'id' => 'content-modal',
    'header' => '<p class="modal-title">提示</p>',
    'bodyOptions' => [
        'class' => 'modal-body modal-body1'
    ],
    // 'footer' => '<a href="#" class="btn btn-primary" data-dismiss="modal">Close</a>',
]);

\yii\bootstrap\Modal::end();

?>

<?php if (!is_null($message)): ?>
    <?php
    $js = "$('#content-modal').modal('show').find('.modal-body').html('" . $message . "');";
    $this->registerJs($js);
    ?>
<?php endif; ?>

<div id="player-content">
    <div class="panel" style="margin-bottom: 10px;">
        <div class="panel-body">
            <div class="row">
                <p class="col-xs-6 of">
                    <?= Yii::t('app.c2', 'ID:') . $playerModel->player_code; ?>
                </p>
                <p class="col-xs-6 of" style="text-align: right">
                    <span id="total-vote-number"><?= $playerModel->total_vote_number ?></span><?= Yii::t('app.c2', 'Vote') ?>
                </p>
            </div>
            <?= $playerModel->title; ?>
        </div>
    </div>

    <div class="panel" style="margin-bottom: 10px;">
        <div class="row statics">
            <div class="col-xs-4">
                <div class="statics-item">
                    <p><?= Yii::t('app.c2', 'Diff Before Player Vote') ?></p>
                    <?= $rankResult['beforeVoteNumber'] . Yii::t('app.c2', 'Vote') ?>
                </div>
            </div>
            <div class="col-xs-4">
                <div class="statics-item">
                    <p><?= Yii::t('app.c2', 'Current Rank') ?></p>
                    <?= $rankResult['currentRank'] . Yii::t('app.c2', 'th') ?>
                </div>
            </div>
            <div class="col-xs-4">
                <div class="statics-item">
                    <p><?= Yii::t('app.c2', 'Diff After Player Vote') ?></p>
                    <?= $rankResult['afterVoteNumber'] . Yii::t('app.c2', 'Vote') ?>
                </div>
            </div>
        </div>
    </div>

    <div class="panel" style="margin-top: 10px">

        <div class="panel-body">

            <?= \frontend\widgets\Swiper::widget(['model' => $playerModel]) ?>

            <?= $playerModel->content ?>

            <div class="btn-group btn-group-justified" role="group" aria-label="ab">
                <div class="btn-group" role="group">
                    <?= \yii\helpers\Html::button(Yii::t('app.c2', 'Free Vote'), [
                        'id' => 'btn-free-vote',
                        'class' => 'btn btn-info',
                        'data-pjax' => 0
                    ]) ?>
                </div>
                <div class="btn-group" role="group">
                    <button type="button" id="btn-gift-vote"
                            class="btn btn-info"><?= Yii::t('app.c2', 'Gift Vote') ?></button>
                </div>
                <?php
                $js = "$('#btn-gift-vote').on('click', function(e) {jQuery('#gifts').toggle();})";
                $this->registerJs($js);
                ?>
            </div>

            <div id="gifts" style="display: none;margin-top: 5px;">
                <?= \frontend\widgets\GiftsGridView::widget(['activityModel' => $activity, 'playerId' => $playerModel->id]) ?>
                <div class="tips">
                    活动重在参与，意在宣传推广，不提倡购买!<br>温馨提示：加油支付失败时，请重新登陆后再次为Ta加油
                </div>
            </div>

        </div>

    </div>

    <div class="panel">
        <div class="panel-body">
            <?= \frontend\widgets\VotedScroll::widget(['player' => $playerModel]) ?>
        </div>
    </div>
</div>

<?php
$voteUrl = \yii\helpers\Url::toRoute('free-vote');
$js = <<<JS
// let container = $("#pjax-container");//容器
$("#pjax-container").on('pjax:send',function(args){window.top.window.showLoading();});
$("#pjax-container").on('pjax:complete',function(args){window.top.window.hideLoading();});
$('#btn-free-vote').on('click', function(e) {
    $.pjax.reload({container:"#pjax-container", url: '{$voteUrl}', data:{id:"{$playerModel->id}"}, replace: false});
});

JS;
$this->registerJs($js);

?>

<?php

// $('#btn-free-vote').on('click', function(e) {
//     $.ajax({
//       type: 'get',
//       url: '{$voteUrl}',
//       dataType: 'html',
//       data: {id:"{$playerModel->id}"},
//       beforeSend: function() {
//         window.top.window.showLoading();
//     },
//       success: function(res) {
//         if (res) {
//             if (res._meta.result === '0000') {
//             }
//             $('#content-modal').find('.modal-title').html('提示');
//             $('#content-modal').modal('show').find('.modal-body').html(res._meta.message);
//         }
//     },
//       error: function(res) {
//         if (res.status === 500) {
//             $('#content-modal').find('.modal-title').html('提示');
//             // $('#content-modal').modal('show').find('.modal-body').html(res.responseText);
//             $('#content-modal').modal('show').find('.modal-body').html('服务器开小差');
//         }
//     },
//       complete: function() {
//         window.top.window.hideLoading();
//     }
// })
//
//
// })

?>

